﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;

public partial class Control_datePickerFromTo : controlMatrix // System.Web.UI.UserControl
{

    public string FromDate
    {
        get
        {
            return DP_From.GetStringDate();
        }
        
    }

    public string ToDate
    {
        get
        {
            return DP_To.GetStringDate();
        }
    }

  

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    /// <summary>
    /// 檢查結束要大於開始日
    /// </summary>
    /// <returns></returns>
    public bool Validate()
    {
        bool ok = true;
        string frm, to;
        frm = DP_From.GetStringDate();
        to = DP_To.GetStringDate();

        if ((!frm.Equals(string.Empty)) & (!to.Equals(string.Empty)))
        {
            //開始不能大於結束
            if (Convert.ToDateTime(frm) > Convert.ToDateTime(to))
            {
                ok = false;
            }
        }
        else
        {
            if ((frm.Equals(string.Empty)) || (to.Equals(string.Empty)))
            {
                ok = false;
            }
        }
        return ok;
    }

    /// <summary>
    /// 回傳From 、To 
    /// </summary>
    /// <returns></returns>
    public List<string> GetBetweenDate()
    {
        List<string> between = new List<string>();
        if (Validate())
        {
            between = new List<string>()
            {DP_From.GetStringDate()
                ,DP_To.GetStringDate()
            };            
        }
        else
        {
            between = new List<string>()
            {string.Empty
                ,string.Empty
            };            
        }
        return between;
    }
}
